<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>spu管理</title>
    <meta content="IE=edge" http-equiv="X-UA-Compatible">
    <!-- 引入样式 -->
    <link href="https://unpkg.com/element-ui/lib/theme-chalk/index.css" rel="stylesheet">
    <link href="../../plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet">
    <link href="../../css/style.css" rel="stylesheet">

    <!-- 上传图片框样式，不使用上传组件可以删除此样式 -->
    <style>
        .avatar-uploader .el-upload {
            border: 1px dashed #d9d9d9;
            border-radius: 6px;
            cursor: pointer;
            position: relative;
            overflow: hidden;
        }

        .avatar-uploader .el-upload:hover {
            border-color: #409EFF;
        }

        .avatar-uploader-icon {
            font-size: 28px;
            color: #8c939d;
            width: 150px;
            height: 70px;
            line-height: 150px;
            text-align: center;
        }

        .avatar {
            width: 150px;
            height: 70px;
            display: block;
        }

    </style>
</head>
<body class="hold-transition">
<div id="app">

    <div class="content-header">
        <h1>管理<small>spu管理</small></h1>
        <el-breadcrumb class="breadcrumb" separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>管理</el-breadcrumb-item>
            <el-breadcrumb-item>spu管理</el-breadcrumb-item>
        </el-breadcrumb>
    </div>

    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <!--查询表单-->
                <el-form :inline="true">
                    <el-form-item label="货号">
                        <el-input class="filter-item" placeholder="货号" v-model="searchMap.sn"></el-input>
                    </el-form-item>
                    <el-form-item label="SPU名">
                        <el-input class="filter-item" placeholder="SPU名" v-model="searchMap.name"></el-input>
                    </el-form-item>
                    <el-form-item label="副标题">
                        <el-input class="filter-item" placeholder="副标题" v-model="searchMap.caption"></el-input>
                    </el-form-item>
                    <el-form-item label="品牌ID">
                        <el-input class="filter-item" placeholder="品牌ID" v-model="searchMap.brandId"></el-input>
                    </el-form-item>
                    <el-form-item label="一级分类">
                        <el-input class="filter-item" placeholder="一级分类" v-model="searchMap.category1Id"></el-input>
                    </el-form-item>
                    <el-form-item label="二级分类">
                        <el-input class="filter-item" placeholder="二级分类" v-model="searchMap.category2Id"></el-input>
                    </el-form-item>
                    <el-form-item label="三级分类">
                        <el-input class="filter-item" placeholder="三级分类" v-model="searchMap.category3Id"></el-input>
                    </el-form-item>
                    <el-form-item label="模板ID">
                        <el-input class="filter-item" placeholder="模板ID" v-model="searchMap.templateId"></el-input>
                    </el-form-item>
                    <el-form-item label="运费模板id">
                        <el-input class="filter-item" placeholder="运费模板id" v-model="searchMap.freightId"></el-input>
                    </el-form-item>
                    <el-form-item label="图片">
                        <el-input class="filter-item" placeholder="图片" v-model="searchMap.image"></el-input>
                    </el-form-item>
                    <el-form-item label="图片列表">
                        <el-input class="filter-item" placeholder="图片列表" v-model="searchMap.images"></el-input>
                    </el-form-item>
                    <el-form-item label="售后服务">
                        <el-input class="filter-item" placeholder="售后服务" v-model="searchMap.saleService"></el-input>
                    </el-form-item>
                    <el-form-item label="介绍">
                        <el-input class="filter-item" placeholder="介绍" v-model="searchMap.introduction"></el-input>
                    </el-form-item>
                    <el-form-item label="规格列表">
                        <el-input class="filter-item" placeholder="规格列表" v-model="searchMap.specItems"></el-input>
                    </el-form-item>
                    <el-form-item label="参数列表">
                        <el-input class="filter-item" placeholder="参数列表" v-model="searchMap.paraItems"></el-input>
                    </el-form-item>
                    <el-form-item label="销量">
                        <el-input class="filter-item" placeholder="销量" v-model="searchMap.saleNum"></el-input>
                    </el-form-item>
                    <el-form-item label="评论数">
                        <el-input class="filter-item" placeholder="评论数" v-model="searchMap.commentNum"></el-input>
                    </el-form-item>
                    <el-form-item label="是否上架">
                        <el-input class="filter-item" placeholder="是否上架" v-model="searchMap.isMarketable"></el-input>
                    </el-form-item>
                    <el-form-item label="是否启用规格">
                        <el-input class="filter-item" placeholder="是否启用规格" v-model="searchMap.isEnableSpec"></el-input>
                    </el-form-item>
                    <el-form-item label="是否删除">
                        <el-input class="filter-item" placeholder="是否删除" v-model="searchMap.isDelete"></el-input>
                    </el-form-item>
                    <el-form-item label="审核状态">
                        <el-input class="filter-item" placeholder="审核状态" v-model="searchMap.status"></el-input>
                    </el-form-item>

                    <el-button @click="fetchData()" class="dalfBut">查询</el-button>
                    <el-button @click="formVisible=true;pojo={}" class="butT" type="primary">新增</el-button>
                </el-form>
            </div>

            <el-table :data="tableData" border style="width: 100%">
                <el-table-column label="主键" prop="id" width="80"></el-table-column>
                <el-table-column label="货号" prop="sn" width="80"></el-table-column>
                <el-table-column label="SPU名" prop="name" width="80"></el-table-column>
                <el-table-column label="副标题" prop="caption" width="80"></el-table-column>
                <el-table-column label="品牌ID" prop="brandId" width="80"></el-table-column>
                <el-table-column label="一级分类" prop="category1Id" width="80"></el-table-column>
                <el-table-column label="二级分类" prop="category2Id" width="80"></el-table-column>
                <el-table-column label="三级分类" prop="category3Id" width="80"></el-table-column>
                <el-table-column label="模板ID" prop="templateId" width="80"></el-table-column>
                <el-table-column label="运费模板id" prop="freightId" width="80"></el-table-column>
                <el-table-column label="图片" prop="image" width="80"></el-table-column>
                <el-table-column label="图片列表" prop="images" width="80"></el-table-column>
                <el-table-column label="售后服务" prop="saleService" width="80"></el-table-column>
                <el-table-column label="介绍" prop="introduction" width="80"></el-table-column>
                <el-table-column label="规格列表" prop="specItems" width="80"></el-table-column>
                <el-table-column label="参数列表" prop="paraItems" width="80"></el-table-column>
                <el-table-column label="销量" prop="saleNum" width="80"></el-table-column>
                <el-table-column label="评论数" prop="commentNum" width="80"></el-table-column>
                <el-table-column label="是否上架" prop="isMarketable" width="80"></el-table-column>
                <el-table-column label="是否启用规格" prop="isEnableSpec" width="80"></el-table-column>
                <el-table-column label="是否删除" prop="isDelete" width="80"></el-table-column>
                <el-table-column label="审核状态" prop="status" width="80"></el-table-column>

                <el-table-column
                        label="操作">
                    <template slot-scope="scope">
                        <el-button @click="edit(scope.row.id)" size="mini"  type="primary">修改</el-button>
                        <el-button @click="dele(scope.row.id)" size="mini"  type="danger">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        :current-page.sync="currentPage"
                        :page-size="size"
                        :page-sizes="[10, 20, 30, 40]"
                        :total="total"
                        @current-change="fetchData"
                        @size-change="fetchData"
                        class="pagiantion"
                        layout="total, sizes, prev, pager, next, jumper">
                </el-pagination>
            </div>
            <div class="add-form">
                <!--弹出窗口-->
                <el-dialog :visible.sync="formVisible" title="编辑">
                    <el-form label-width="80px">
                        <el-form-item label="货号">
                            <el-input v-model="pojo.sn"></el-input>
                        </el-form-item>
                        <el-form-item label="SPU名">
                            <el-input v-model="pojo.name"></el-input>
                        </el-form-item>
                        <el-form-item label="副标题">
                            <el-input v-model="pojo.caption"></el-input>
                        </el-form-item>
                        <el-form-item label="品牌ID">
                            <el-input v-model="pojo.brandId"></el-input>
                        </el-form-item>
                        <el-form-item label="一级分类">
                            <el-input v-model="pojo.category1Id"></el-input>
                        </el-form-item>
                        <el-form-item label="二级分类">
                            <el-input v-model="pojo.category2Id"></el-input>
                        </el-form-item>
                        <el-form-item label="三级分类">
                            <el-input v-model="pojo.category3Id"></el-input>
                        </el-form-item>
                        <el-form-item label="模板ID">
                            <el-input v-model="pojo.templateId"></el-input>
                        </el-form-item>
                        <el-form-item label="运费模板id">
                            <el-input v-model="pojo.freightId"></el-input>
                        </el-form-item>
                        <el-form-item label="图片">
                            <el-input v-model="pojo.image"></el-input>
                        </el-form-item>
                        <el-form-item label="图片列表">
                            <el-input v-model="pojo.images"></el-input>
                        </el-form-item>
                        <el-form-item label="售后服务">
                            <el-input v-model="pojo.saleService"></el-input>
                        </el-form-item>
                        <el-form-item label="介绍">
                            <el-input v-model="pojo.introduction"></el-input>
                        </el-form-item>
                        <el-form-item label="规格列表">
                            <el-input v-model="pojo.specItems"></el-input>
                        </el-form-item>
                        <el-form-item label="参数列表">
                            <el-input v-model="pojo.paraItems"></el-input>
                        </el-form-item>
                        <el-form-item label="销量">
                            <el-input v-model="pojo.saleNum"></el-input>
                        </el-form-item>
                        <el-form-item label="评论数">
                            <el-input v-model="pojo.commentNum"></el-input>
                        </el-form-item>
                        <el-form-item label="是否上架">
                            <el-input v-model="pojo.isMarketable"></el-input>
                        </el-form-item>
                        <el-form-item label="是否启用规格">
                            <el-input v-model="pojo.isEnableSpec"></el-input>
                        </el-form-item>
                        <el-form-item label="是否删除">
                            <el-input v-model="pojo.isDelete"></el-input>
                        </el-form-item>
                        <el-form-item label="审核状态">
                            <el-input v-model="pojo.status"></el-input>
                        </el-form-item>

                        <!-- 图片上传代码 如页面有图片上传功能放开注释 ****
                        <el-form-item label="图片">
                            <el-upload
                                    class="avatar-uploader"
                                    action="/upload/native.do"
                                    :show-file-list="false"
                                    :on-success="handleAvatarSuccess"
                                    :before-upload="beforeAvatarUpload">
                                <img v-if="imageUrl" :src="imageUrl" class="avatar">
                                <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                            </el-upload>
                        </el-form-item>
                        -->

                        <el-form-item>
                            <el-button @click="save()" type="primary">保存</el-button>
                            <el-button @click="formVisible = false">关闭</el-button>
                        </el-form-item>
                    </el-form>
                </el-dialog>
            </div>

        </div>
    </div>


</div>
</body>
<script src="../../js/vue.js"></script>
<script src="../../js/axios.js"></script>
<script src="../../js/elementui.js"></script>
<script>
    new Vue({
        el: '#app',
        data() {
            return {
                tableData: [],
                currentPage: 1,
                total: 10,
                size: 10,
                searchMap: {},
                pojo: {},
                formVisible: false,
                imageUrl: ''
            }
        },
        created() {
            this.fetchData();
        },
        methods: {
            fetchData() {
                axios.post(`/spu/findPage?page=${this.currentPage}&size=${this.size}`, this.searchMap).then(response => {
                    this.tableData = response.data.rows;
                    this.total = response.data.total;
                });
            },
            save() {
                // this.pojo.image= this.imageUrl; //如页面有图片上传功能放开注释
                axios.post(`/spu/${this.pojo.id == null ? 'add' : 'update'}`, this.pojo).then(response => {
                    this.fetchData(); //刷新列表
                    this.formVisible = false;//关闭窗口
                });
            },
            edit(id) {
                this.formVisible = true // 打开窗口
                // 调用查询
                axios.get(`/spu/findById?id=${id}`).then(response => {
                    this.pojo = response.data;
                    // this.imageUrl=this.pojo.image //显示图片  如页面有图片上传功能放开注释
                })
            },
            dele(id) {
                this.$confirm('确定要删除此记录吗?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    axios.get(`/spu/delete.do?id=${id}`).then(response => {
                        this.fetchData(); //刷新列表
                    })
                })
            },
            /* ****图片上传相关代码  如页面有图片上传功能放开注释 ****
            handleAvatarSuccess(res, file) {
                this.imageUrl = file.response;
            },
            beforeAvatarUpload(file) {
                const isJPG = file.type === 'image/jpeg';
                const isLt2M = file.size / 1024 / 1024 < 2;

                if (!isJPG) {
                    this.$message.error('上传头像图片只能是 JPG 格式!');
                }
                if (!isLt2M) {
                    this.$message.error('上传头像图片大小不能超过 2MB!');
                }
                return isJPG && isLt2M;
            }*/
        }
    })
</script>
</html>
